/*
 * MethodInvocationInfoPredicate.java
 *
 * Created on 21.05.2007, 19:15:07
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package logrus.beanmock.invoker;

import java.lang.reflect.Method;

import org.apache.commons.collections.Predicate;

/**
 *
 * @author serge
 */
public class MethodInvocationInfoPredicate implements Predicate {
    
    private final Object target;
    
    private final Method method;
    
    private final CounterAccessor counterAccessor;
    
    public MethodInvocationInfoPredicate(final Object target, final Method method, final CounterAccessor counterAccessor) {
        this.target = target;
        this.method = method;
        this.counterAccessor = counterAccessor;
    }

    public boolean evaluate(Object obj) {
        MethodInvocationInfo info = (MethodInvocationInfo) obj;
        if (!info.getTargetClass().isInstance(target)) {
            return false;
        }
        if (!info.getMethodName().equals(method.getName())) {
            return false;
        }
        Counter counter = counterAccessor.getCounter(info);
        return !counter.isFinished();
    }
    
}
